/**
 * Input - L5
 *
 * @author dev@lonphy.com
 * @version 0.1
 */
(function(L5){
	"use strict";
	class L5Mouse {
		constructor() {
			this.lastX = 0;	// 鼠标最后X坐标
			this.lastY = 0; //  鼠标最后Y坐标

			this._lastZoom = 1; // 滚轮level

			this.sensitivity = 0.1;	// 鼠标灵敏度

			this._yaw = 0;
			this._pitch = 0;

			L5Mouse.init(this);
		}
		static init(scope) {
			window.addEventListener('mousemove', L5Mouse.moveHandler.bind(scope), false);
			window.addEventListener('mousewheel', L5Mouse.wheelHandler.bind(scope), false);
		}

		static moveHandler (e) {
			e.stopPropagation();
			let xOffset = this.lastX - e.x,
				yOffset = this.lastY - e.y,
				sensitivity = this.sensitivity;
			this.lastX = e.x;
			this.lastY = e.y;

			xOffset *= sensitivity;
			yOffset *= sensitivity;

			this._yaw   += xOffset;
			this._pitch += yOffset;
			if(this._pitch > 89.99) this._pitch = 89.99;
			if(this._pitch < -89.99) this._pitch = -89.99;
		}
		get lastZoom() {
			var ret = this._lastZoom;
			this._lastZoom = 0;
			return ret*this.sensitivity*5;
		}
		get yaw() {
			return this._yaw*Math.PI/180;
		}
		get pitch() {
			return this._pitch*Math.PI/180;
		}
		static wheelHandler (e) {
			e.stopPropagation();
			this._lastZoom = e.wheelDelta/120;
		}
	}

	L5.Input.L5Mouse = new L5Mouse();
})(window.L5);